package com.wootion.cims.module.communityresidence.occupancy.controller;

import com.wootion.cims.module.communityresidence.occupancy.dto.OccupancyDto;
import com.wootion.cims.module.communityresidence.occupancy.dto.PageQueryOcc;
import com.wootion.cims.module.communityresidence.occupancy.excel.ExcelRules;
import com.wootion.cims.module.communityresidence.occupancy.service.OccupancyService;
import com.wootion.cims.module.systemsetting.dictionary.model.LogAnotion;
import com.wootion.cims.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:
 * @Date: 2022/12/15/10:30
 * @Description:
 */
@RestController
@Api(value = "入住情况")
@RequestMapping(path = {"/occupancy"})
public class OccupancyController {
    @Resource
    private OccupancyService occupancyService;

    /**
     * 列表查询
     * @param pageQueryOcc
     * @return
     */
    @PostMapping(path = {"/list"})
    @RequiresAuthentication
    @ApiOperation(value = "入住情况-社区列表查询", httpMethod = "POST",notes = "不是jso格式,而是K-V结构,例如：condition:name page:2 limit:20")
    public ResponseResult list(@RequestBody PageQueryOcc pageQueryOcc){
        return occupancyService.list(pageQueryOcc);
    }

    /**
     * 根据房屋id,查询当前业主以及关联的所有入住人员(包括业主自身)信息
     * @param id
     * @return
     */
    @GetMapping(path = {"/find"})
    @RequiresAuthentication
    @ApiOperation(value = "入住情况-修改入住人员信息", httpMethod = "GET",notes = "personId=1")
    public ResponseResult find(@RequestParam("id") String id){
        return occupancyService.find(id);
    }

    /**
     * 修改入住情况
    * @return
     */
    @PostMapping(path = {"/update/save"})
    @RequiresAuthentication
    @ApiOperation(value = "修改入住情况", httpMethod = "POST",notes = "{id:1,personList:[{},{}]}")
    public ResponseResult updateSave(@RequestBody OccupancyDto occupancyDto, HttpServletRequest request){
        return occupancyService.updateSave(occupancyDto,request);
    }
    
    /**
     * 导出住宅列表
     * @param excelRules
     * @return
     */
    @PostMapping(path = {"/excel"})
    @RequiresAuthentication
    @LogAnotion(type = "导出",value = "1",incident = "入住信息",prefixContent = "执行导出操作")
    @ApiOperation(value = "社区管理-导出入住列表", httpMethod = "POST",notes = "{\"ids\":[\"002443e3023366e6d984284134c63525\",\"09dbd05b9356f3cafae3d3bd7ced4b61\"]}")
    public ResponseResult occupancyExcel(@RequestBody ExcelRules excelRules){
        return occupancyService.occupancyExcel(excelRules);
    }

    /**
     * excel导出
     * @param filePath
     * @param response
     * @return
     */
    @GetMapping(path = {"/download"})
    @ApiOperation(value = "excel下载")
    public ResponseResult download(String filePath,HttpServletResponse response){
        return occupancyService.download(filePath,response);
    }
}
